from rich.console import Console
from rich.prompt import Prompt
from rich.panel import Panel
import math

console = Console()

def calculator():
    console.print(Panel("科学计算器", title_align="center"))
    while True:
        expr = Prompt.ask("输入表达式（输入 /exit 退出）")
        if expr == "/exit":
            break
        try:
            # 支持数学函数
            result = eval(expr, {"__builtins__": None}, math.__dict__)
            console.print(f"[green]{expr} =[/green] [bold]{result}[/bold]")
        except Exception as e:
            console.print(f"[bold red]错误:[/bold red] {str(e)}")

calculator()